<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 300px;
            margin: 10px auto;
        }

        input {
            width: 60px;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="text" class="aa">
        &nbsp; +
        <input type="text" class="bb">
        &nbsp; = &nbsp;
        <span id="sum">?</span>
        &nbsp;
        <input type="button" value="求和" id="btn">

    </div>
</body>

<script>
    var input = document.getElementsByTagName('input')  // san个input框

    for (var i = 0; i < 2; i++) {

        input[i].onkeyup = function () {
            this.value = this.value.replace(/[^\d|","]/, "")
        }

        input[2].onclick = function () {
            var a = document.querySelector('.aa').value // 第一个input框
            var b = document.querySelector('.bb').value // 第二个input框
            var sum = document.getElementById('sum') // 总数
            console.log(sum);

            var c = 0

            c += parseInt(a) + parseInt(b)

            sum.innerHTML = c


        }

    }
</script>

</html>